<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .mycolor {
            color: red;
        }
        
        .myborder {
            border: 1px blueviolet solid
        }
    </style>
</head>

<body>
    <div id="div1" style="color: red;" class="myborder" title="div1"> 这是一个div1 </div>
    <div id="div2"></div>
    <div id="div3" class="mycolor"></div>
    <div id="div4" class="mycolor">
        <p id="p1">ppp</p>
        <span id="span1">span</span>
    </div>
    <ul>
        <li>香蕉</li>
        <li>苹果</li>
        <li>橘子</li>
    </ul>

    <script>
        // 查找元素
        let div1 = document.getElementById("div1")
        console.log(div1)
        div1.innerHTML = "<p>122121212</p>"
        let myEle = document.createElement("div")
        myEle.innerHTML = "这是我创建的"
        div1.append(myEle)
        div1.append("666")
        div1.prepend("0000000")

        let div2 = document.querySelector("#div2")
        console.log(div2)
        let div3 = document.querySelector(".mycolor")
            // 插入元素
        let divs = document.getElementsByTagName("div")
        console.log(divs)
        let p1 = document.getElementById("p1")
        let myEle2 = document.createElement("h3")
        myEle2.innerHTML = "h3"
        let myEle3 = document.createElement("h5")
        myEle3.innerHTML = "hhh"
        divs[4].insertBefore(myEle2, p1)
        p1.before(myEle2)
        p1.after(myEle3)
            // 删除元素
        let span1 = document.getElementById("span1")
        span1.remove() //简单方式
            //复杂方式删除
            // 1.获取元素（重要）
        let list = document.getElementsByTagName("ul")
        console.log(list) //获取的是集合
            //获取某个元素的所有子元素用.children
            // for (item of list[0].children) {
            //     item.innerHTML = "猕猴桃"
            // }
        console.log(list[0].firstElementChild) //获取第一个元素孩子
        console.log(list[0].firstElementChild.nextElementSibling) //获取第一个元素孩子的元素兄弟姐妹
        console.log(list[0].firstElementChild.nextSibling.nextSibling)
            //换行之后有个文本节点，空白的文本节点
        list[0].children[0]
        console.log(p1.parentElement)
        p1.parentElement.removeChild(p1) //复杂方式删除
        let li1 = list[0].children[1]
            // li1.remove()
            // li1.parentElement.removeChild(li1)

        //js操作属性一
        let div5 = document.getElementById("div1")
        div5.title = "xxx"
        div5.style.color = "blue"
        div5.style.backgroundColor = "green"

        //js操作属性二
        div5.setAttribute("title", "yyy")
        div5.getAttribute("title")
    </script>
</body>

</html>